'use strict'

class wearbook {

  constructor () {
    //param默认就是/:id，若要改变路由，则可以设置此属性，比如设置为/:name
    //this.param = '/:id'
  }

  //以下方法，若不需要，要去掉，避免无意义的路由。

  //获取资源具体内容
  async get(c) {
    let sqltext = `SELECT * FROM wear WHERE wear_id = $1`;
    let r = await c.service.psql.query(sqltext, [c.param.id]);
    if (r.rowCount <= 0) return c.status(404).send('not found');
    c.send(JSON.stringify(r.rows[0]));
  }

  async list(c) {
    let sqltext = `SELECT * FROM wear`;
    let r = await c.service.psql.query(sqltext);
    c.send(JSON.stringify(r.rows));
  }

  // //?offset=XX;
  // async list (c) {
  //   let offset = c.query.offset || 0;    
  //   if (isNaN(offset)) offset = 0;
  //   let sqltext = `SELECT food_id,food_name,food_image FROM eat ORDER BY food_time DESC LIMIT 1000 OFFSET $1`;
  //   let r = await c.service.psql.query(sqltext, [offset]);
  //   c.send(JSON.stringify(r.rows));
  // }
}

module.exports = wearbook;